Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the PollAnswers class.
	''' </summary>
	<Serializable> _
	Public Partial Class PollAnswersCollection 
	Inherits ActiveList(Of PollAnswers, PollAnswersCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the PollAnswers table.
	''' </summary>
	<Serializable> _
	Public Partial Class PollAnswers 
	Inherits ActiveRecord(Of PollAnswers)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("PollAnswers", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarPollAnswerId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPollAnswerId.ColumnName = "PollAnswerId"
                colvarPollAnswerId.DataType = DbType.Guid
                colvarPollAnswerId.MaxLength = 0
                colvarPollAnswerId.AutoIncrement = false
                colvarPollAnswerId.IsNullable = false
                colvarPollAnswerId.IsPrimaryKey = true
                colvarPollAnswerId.IsForeignKey = false
                colvarPollAnswerId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarPollAnswerId)
                
                Dim colvarQuestionId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarQuestionId.ColumnName = "QuestionId"
                colvarQuestionId.DataType = DbType.Guid
                colvarQuestionId.MaxLength = 0
                colvarQuestionId.AutoIncrement = false
                colvarQuestionId.IsNullable = false
                colvarQuestionId.IsPrimaryKey = false
                colvarQuestionId.IsForeignKey = true
                colvarQuestionId.IsReadOnly = false
                
                
				colvarQuestionId.ForeignKeyTableName = "PollQuestions"
                
                schema.Columns.Add(colvarQuestionId)
                
                Dim colvarAnswer As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarAnswer.ColumnName = "Answer"
                colvarAnswer.DataType = DbType.String
                colvarAnswer.MaxLength = 80
                colvarAnswer.AutoIncrement = false
                colvarAnswer.IsNullable = false
                colvarAnswer.IsPrimaryKey = false
                colvarAnswer.IsForeignKey = false
                colvarAnswer.IsReadOnly = false
                
                
                schema.Columns.Add(colvarAnswer)
                
                Dim colvarRank As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarRank.ColumnName = "Rank"
                colvarRank.DataType = DbType.Int32
                colvarRank.MaxLength = 0
                colvarRank.AutoIncrement = false
                colvarRank.IsNullable = true
                colvarRank.IsPrimaryKey = false
                colvarRank.IsForeignKey = false
                colvarRank.IsReadOnly = false
                
                
                schema.Columns.Add(colvarRank)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("PollAnswers",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("PollAnswerId")> _
        Public Property PollAnswerId As Guid 
			Get
				Return GetColumnValue(Of Guid)("PollAnswerId")
			End Get
		    
			Set
				SetColumnValue("PollAnswerId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("QuestionId")> _
        Public Property QuestionId As Guid 
			Get
				Return GetColumnValue(Of Guid)("QuestionId")
			End Get
		    
			Set
				SetColumnValue("QuestionId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Answer")> _
        Public Property Answer As String 
			Get
				Return GetColumnValue(Of String)("Answer")
			End Get
		    
			Set
				SetColumnValue("Answer", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Rank")> _
        Public Property Rank As Nullable(Of Integer) 
			Get
				Return GetColumnValue(Of Nullable(Of Integer))("Rank")
			End Get
		    
			Set
				SetColumnValue("Rank", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
	    #Region "PrimaryKey Methods"
	    
			Public Function PollVotesRecords() As Data.PollVotesCollection 
	
				Return New Data.PollVotesCollection().Where(PollVotes.Columns.PollAnswerId, PollAnswerId).Load()
	
			End Function
			
		#End Region
		
		
		
		
		
		
	    
	    #Region "ForeignKey Methods"
	    
		''' <summary>
		''' Returns a PollQuestions ActiveRecord object related to this PollAnswers
		''' </summary>
		Public Property PollQuestions() As Data.PollQuestions
			Get
				Return Data.PollQuestions.FetchByID(Me.QuestionId)
			End Get
			Set
				SetColumnValue("QuestionId", Value.PollId)
			End Set
		End Property
	    
	    #End Region
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varPollAnswerId As Guid,ByVal varQuestionId As Guid,ByVal varAnswer As String,ByVal varRank As Nullable(Of Integer))
			Dim item As PollAnswers = New PollAnswers()
			
            item.PollAnswerId = varPollAnswerId
            
            item.QuestionId = varQuestionId
            
            item.Answer = varAnswer
            
            item.Rank = varRank
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varPollAnswerId As Guid,ByVal varQuestionId As Guid,ByVal varAnswer As String,ByVal varRank As Nullable(Of Integer))
			Dim item As PollAnswers = New PollAnswers()
		    
                item.PollAnswerId = varPollAnswerId
				
                item.QuestionId = varQuestionId
				
                item.Answer = varAnswer
				
                item.Rank = varRank
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared PollAnswerId As String = "PollAnswerId"
            
            Public Shared QuestionId As String = "QuestionId"
            
            Public Shared Answer As String = "Answer"
            
            Public Shared Rank As String = "Rank"
            
		End Structure
		#End Region
	End Class
End Namespace
